//
//  UIViewController+C.m
//  ExchangeImp
//
//  Created by fangshufeng on 2018/3/23.
//  Copyright © 2018年 fangshufeng. All rights reserved.
//

#import "UIViewController+C.h"
#import <objc/runtime.h>

@implementation UIViewController (C)

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSLog(@"---C-被加载了--");
        Class class = [self class];
        
        SEL originalSelector = @selector(presentViewController:animated:completion:);
        SEL swizzledSelector = @selector(cAlertPresentViewController:animated:completion:);
        
        Method originalMethod = class_getInstanceMethod(class, originalSelector);
        Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
        NSLog(@"C-begin---%p-----%p",method_getImplementation(originalMethod),method_getImplementation(swizzledMethod));
        method_exchangeImplementations(originalMethod, swizzledMethod);
        
        NSLog(@"C-after---%p-----%p",method_getImplementation(originalMethod),method_getImplementation(swizzledMethod));
        
    });
}

- (void)cAlertPresentViewController:(UIViewController *)viewControllerToPresent
                           animated:(BOOL)flag
                         completion:(void (^)(void))completion {
    NSLog(@"---C-被执行了--");
    [self cAlertPresentViewController:viewControllerToPresent
                             animated:flag
                           completion:completion];
}


@end
